<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CRM系统</title>
</head>
<body class="backgroud">
<div id="app" >
    <!--登录对话框   用户登录表单
        使用回调函数来强制用户不能点击空白处也不能关闭该登录窗口-->
    <el-dialog title="CRM系统入口" :visible.sync="dialogLogin"
               :show-close="false"
               :close-on-click-modal="false"
               width="20%" center>
        <el-form :model="user" :rules="rules" ref="user" class="demo-ruleForm">
            <el-form-item label="账号" prop="tel">
                <el-input v-model="user.tel"></el-input><!-- v-model=""-->
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input  v-model="user.password" show-password></el-input><!--v-model="user.password"-->
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="login">登录</el-button>
            <el-button type="primary" @click="user_register">注册</el-button>
        </div>
    </el-dialog>
    <!--用户注册表单 -->
    <el-dialog title="注册"
               :show-close="false"
               :close-on-click-modal="false"
               :visible.sync="dialogRegister" width="25%" center>
        <el-form :model="user" :rules="rules" ref="user" label-width="80px" class="demo-ruleForm"
                 :label-position="labelPosition">
            <el-form-item label="昵称" prop="userName" >
                <el-input v-model="user.userName"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
                <el-input v-model="user.password" show-password></el-input>
            </el-form-item>
            <el-form-item label="职位" prop="position">
                <el-input v-model="user.position"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="description" >
                <el-input v-model="user.description"></el-input>
            </el-form-item>
            <el-form-item label="电话号码" prop="tel">
                <el-input v-model="user.tel"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="register">注册</el-button>
            <el-button type="primary" @click="dialogRegister = false">取消</el-button>
        </div>
    </el-dialog>
</div>



<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../element-ui/lib/index.js"></script>
<link rel="stylesheet" href="../element-ui/lib/theme-chalk/index.css">
<script>Vue.config.productionTip = false</script>
<script>
    new Vue({
        el:"#app",
        mounted(){

        },
        methods:{
            //2 单击登录键 提交表单，发送Ajax请求
            login() {
                axios.get("/user/"+this.user.tel+"/"+this.user.password).then((resp) => {
                    console.log(resp.data)
                        if (resp.data.flag) {
                            sessionStorage.obj = JSON.stringify(resp.data.data);
                            window.location.href="/pages/crm.html";
                        } else {
                            this.$message.error(resp.data.msg);
                        }
                })
            },
            //单击注册 弹出用户注册表单
            user_register(){
                this.user={};
                this.dialogRegister=true;

            },
            //发送Ajax请求
            register(){
                axios.post("/user/",this.user).then((resp)=>{
                    if(resp.data.flag){
                        //关闭窗口
                        this.dialogRegister = false;
                        //弹出消息提示
                        this.$message({
                            message: resp.data.msg,
                            type: 'success'
                        });
                    }else{
                        this.$message.error(resp.data.msg);
                    }
                })
            },

        },
        data(){
            return {
                //用户数据模型
                user: {
                    uid: '',
                    userName: '',
                    password: '',
                    position: '',
                    description: '',
                    tel:''
                },
                dialogLogin: true,
                //注册对话框是否可见
                dialogRegister: false,
                labelPosition: 'left',
                rules: {
                    userName: [
                        { required: true, message: '请输入账户昵称', trigger: 'change' }
                    ],
                    password: [
                        { required: true, message: '请设置登录密码', trigger: 'change' },
                        { min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur' }
                    ],
                    position: [
                        { required: true, message: '请输入账户职位', trigger: 'change' }
                    ],
                    description: [
                        { required: true, message: '请输入详细信息', trigger: 'change' }
                    ],
                    tel: [
                        { required: true, message: '请填写联系电话', trigger: 'blur' }
                    ],
                },
            }
        }
    })
</script>
<style scoped>
    .backgroud {
        width: 100%;
        height: 100%;
        background-image: url("../img/loginBackgroud.png");
        background-size: cover;
        background-position: center;
        position: relative;
    }
</style>
</body>
</html>